package com.example.firstjavamqtt.factory.strategy.DeviceLogMessage;

import com.alibaba.fastjson.JSONObject;
import com.example.firstjavamqtt.common.excepiton.GlobalException;
import com.example.firstjavamqtt.common.result.ResultCodeEnum;
import com.example.firstjavamqtt.model.device.InfraredMonitor;

//生成红外人体检测的设备日志策略
public class InfraredMonitorMessageLogStrategy implements DeviceLogMessageStrategy{

    @Override
    public String getOperation(String string) {
        InfraredMonitor infraredMonitor = JSONObject.parseObject(string, InfraredMonitor.class);
        if(!infraredMonitor.isOnline()){
            throw new GlobalException(ResultCodeEnum.OFFLINE);
        }
        if(infraredMonitor.getAlarm()==1){
            return "有人走过";
        }
        return "无人走过";
    }
}
